<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>阳曲服务区信息平台</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/bootstrap.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/font-awesome.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/AdminLTE.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/all-skins.min.css">
  <link rel="stylesheet" href="${request.contextPath}/statics/css/main.css">
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>
<body class="hold-transition login-page" onload="load();" style="background: url(../../statics/css/img/aa.png) no-repeat;">
<div class="login-box" >
  <div class="login-logo">
    <b>系统授权</b>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body" style="width: 360px;">
      <div class="form-group has-feedback">
          <label>机器码：</label>
          <input type="text" placeholder="机器码" class="form-control" id="code"  readonly="readonly" style="padding: 0;" >
      </div>
      <div class="form-group has-feedback" style="margin-top: 20px;">
          <label>选择授权文件</label>
              <input type="file" name="licenceFile" style="width: 320px;" accept=".lic" id="licenceFile"/>
              <input value="上传授权文件" class="btn btn-primary btn-block btn-flat" style="margin-top: 20px;" onclick="upload()"/>
      </div>
  </div>
</div>
<script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script src="${request.contextPath}/statics/libs/vue.min.js"></script>
<script src="${request.contextPath}/statics/libs/bootstrap.min.js"></script>
<script src="${request.contextPath}/statics/libs/jquery.slimscroll.min.js"></script>
<script src="${request.contextPath}/statics/libs/fastclick.min.js"></script>
<script src="${request.contextPath}/statics/libs/app.js"></script>
<script src="${request.contextPath}/statics/plugins/layer/layer.js"></script>
<script type="text/javascript">
    function load() {
        $.get("authorize/getLicenceCode", function(r){
            $("#code").val(r.code);
        });
    }
    function upload(){
        var formData = new FormData();
        var file = $("#licenceFile")[0].files[0];
        if(file == undefined){
            layer.msg("授权文件不能为空",{icon:5});
            return;
        }
        var name = file.name;
        if(name.split(".")[1] != "lic"){
            layer.msg("授权文件格式不正确",{icon:5});
            return;
        }
        formData.append("file", $("#licenceFile")[0].files[0]);
        $.ajax({
            url: "authorize/uploadLicence",
            type: "POST",
            data: formData,
            /**
             *必须false才会自动加上正确的Content-Type
             */
            contentType: false,
            /**
             * 必须false才会避开jQuery对 formdata 的默认处理
             * XMLHttpRequest会对 formdata 进行正确的处理
             */
            processData: false,
            success: function (data) {
                layer.msg("授权文件上传成功",{icon:6});
                window.setTimeout("window.location.href='login.html'",1000);
            },
            error: function () {
                alert("上传失败！");
            }
        });
    }

</script>
</body>
</html>
